package snaptest.tool.ui;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;

public class SnapTestToolView {

	private JFrame frame;

	private JList fileList;

	private JTextField referenceText, newText;

	public JFrame getFrame() {
		if (frame == null) {
			frame = new JFrame("Snap Test Tool");
			frame.setSize(800, 600);
			frame.add(createTopLevelPane());
		}
		return frame;
	}

	private JSplitPane createTopLevelPane() {
		JSplitPane topLevelPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		topLevelPane.setTopComponent(new JScrollPane(getFileList()));
		topLevelPane.setBottomComponent(createDiffPane());
		return topLevelPane;
	}

	private JSplitPane createDiffPane() {
		JSplitPane diffPane = new JSplitPane();
		diffPane.setLeftComponent(new JScrollPane(getReferenceTextField()));
		diffPane.setRightComponent(new JScrollPane(getNewTextField()));
		return diffPane;
	}

	public JList getFileList() {
		if (fileList == null) {
			fileList = new JList();
		}
		return fileList;
	}

	public JTextField getReferenceTextField() {
		if (referenceText == null) {
			referenceText = new JTextField();
		}
		return referenceText;
	}

	public JTextField getNewTextField() {
		if (newText == null) {
			newText = new JTextField();
		}
		return newText;
	}

	public void show() {
		getFrame().setVisible(true);
	}
}
